package com.mf.mysql.connectors.service.batisutils.JDBCutils;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

/**
 * @PACKAGE_NAME: com.mf.mysql.connectors.service.batisutils.JDBCutils
 * @NAME: PrintSQLStatement
 * @USER: 马飞飞
 * @DATE: 2021/8/8   19:25
 * @TIME: 19:25
 * @YEAR: 2021
 * @MONTH: 08
 */
public final class PrintSQLStatement {
    public void readSql(String sql) {
        System.out.println("SQL ===> " + sql);
        System.out.println(" SQL >>>Parameter");
    }

    public void readParameter(Map<String, Object> map) {
        if (map != null) {
            Set<String> strings = map.keySet();
            for (String s : strings) {
                String sv = s;
                if (s.contains("or ") || s.contains(" or ")) {
                    sv = sv.replace("or ", "");
                }
                if (s.contains(" like") || s.contains(" like ")) {
                    sv = sv.replace(" like", "");
                }
                System.out.println("  Parameter ===> " + sv + " => " + map.get(s));
            }
        } else {
            System.out.println("  Parameter ===> null");
        }
    }

    public void readParameter(Serializable[] mod) {
        if (mod != null) {
            for (Serializable serializable : mod) {
                System.out.println("  Parameter ===> " + serializable);
            }
        } else {
            System.out.println("  Parameter ===> null");
        }
    }

    public void readParameter(Serializable id) {
        if (id != null) {
            System.out.println("  Parameter ===> " + id);
        } else {
            System.out.println("  Parameter ===> null");
        }
    }
    public void readParameter(Object... ob) {
        if (ob != null) {
            for (Object o : ob) {
                System.out.println("  Parameter ===> " + o.toString());
            }
        } else {
            System.out.println("  Parameter ===> null");
        }
    }
    public void readParameter(){
        System.out.println("  Parameter ===> null");
    }
}
